﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Setting_do_SaveDept : SessionPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //deptID: $("#DeptID").val(), deptName: $("#DeptName").val(), parentID: $("#ParentDeptID").val()
        string deptID = Request.Form["deptID"] + "";
        string deptName = Request.Form["deptName"] + "";
        string parentID = Request.Form["parentID"] + "";

        LogicLayer mgr = new LogicLayer();

        if (string.IsNullOrEmpty(parentID))
            Response.End();

        if (deptID == "")
        {
            SYS_Department dept = new SYS_Department();
            dept.DeptID = Guid.NewGuid().ToString();
            dept.ParentID = parentID;
            dept.DeptName = deptName;
            if (mgr.AddSYS_Department(dept))
                Response.Write("ok");
            else
                Response.Write("failed");
        }
        else
        {
            SYS_Department dept = mgr.GetSYS_Department(deptID);
            dept.ParentID = parentID;
            dept.DeptName = deptName;
            if (mgr.UpdateSYS_Department(dept))
                Response.Write("ok");
            else
                Response.Write("failed");            
        }
    }
}